const state = {
    models: [],
    typeArray: [
        { label: 'Char', value: 'Char' },
        { label: 'Integer', value: 'Integer' },
        { label: 'Boolean', value: 'Boolean' },
        { label: 'Date', value: 'Date' },
        { label: 'Long', value: 'Long' },
        { label: 'Float', value: 'Float' },
        { label: 'Double', value: 'Double' },
        { label: 'String', value: 'String' },
        { label: 'Short', value: 'Short' },
        { label: 'Byte', value: 'Byte' },
    ],
};
const getters = {};
const mutations = {};
const actions = {
    getRenderData(context) {
        // action=> 获取全部Key值
        window.action.model.getAll().then((res) => {
            if (res) {
                for (let i = 0; i < res.length; i++) {
                    const element = res[i];
                    element.show = false;
                    element.itemArray = JSON.parse(element.text);
                    for (let i = 0; i < element.itemArray.length; i++) {
                        const item = element.itemArray[i];
                        if (!item.checked) {
                            item.checked = false;
                        };
                    };
                    element.text = '';
                };
                context.state.models = res;
            };
        });
    },
    creatModel(context, param) {
        window.action.model.creat({
            key: param.key,
            name: param.name,
            text: JSON.stringify(param.itemArray)
        }).then((res) => {
            if (res) {
                param.callback();
                context.dispatch('getRenderData');
            };
        });
    },
    updateModel(context, param) {
        window.action.model.update({
            id: param.id,
            key: param.key,
            name: param.name,
            text: JSON.stringify(param.itemArray)
        }).then((res) => {
            if (res) {
                param.callback();
                context.dispatch('getRenderData');
            };
        });
    },
    deleteModel(context, id) {
        window.action.model.delete(id).then((res) => {
            if (res) {
                context.dispatch('getRenderData');
            };
        });
    },
};

export default {
    namespaced: true,
    state,
    getters,
    mutations,
    actions
}